let $ = (sel) => document.querySelector(sel);
// 删除前导空格
let ltrim = (str) => str.replace(/^\s*/g,'');
let rtrim = (str) => str.replace(/\s*$/g,'');
let trim = (str) => str.replace(/(^\s*)|(\s*$)/g,'');
let ipt = $('#ipt'),
    regEle = $('#reg'),
    rsEle = $('#rs');

ipt.addEventListener('blur',(e) => {
    let val = trim(ipt.value);
    // let reg = /^\d/;     // 包含数字
    // let reg = /\w$/;
    //let reg = /^[a-z]\d$/;
    //let reg = /^[a-z0-9A-Z_]oo\w/;
    // let reg = /^1[^012]\d{9}$/;
    //let reg = /^[\w]+@[a-z0-9]+\.(com|cn|com.cn|net|org)$/;
    //let reg = /^http(s)?:\/\/(www\.)?[a-z\d]+\.(com|cn|com.cn|net|org)(\?(&?[\w]+=[\w\u4e00-\u9fa5]+)*)?$/;
    // http://www.baidu.com
    // https://jd.com
    // http://jd.com?参数=参数值&参数=参数值
    // http或https开头
    // www.   可以没有，有只能有1次
    //let rs = val.match(reg);
    // let rs = reg.exec(val);
    //let rs = reg.test(val);
    // 语法：正则.test(str)
    // 功能：boolean
    let reg = /淘宝/g;
    let rs = val.replace(reg,'🍑');
    regEle.innerHTML = reg;
    console.log(rs);
    rsEle.innerHTML = rs;
    console.log(val.length);
})

let str = 'I5Love2You0';
let ns = str.replace(/\d/g,'~~~');

let new_str = str.replace(/\d/g,($0)=>{
    return  $0 + '0';
});
console.log(new_str);

let attr = 'get-element-by-id';   // getElementById
let formatStr = attr.replace(/-([a-z])/g,function($0,$1){
    //return $0;
    //return $0.substr(1).toUpperCase();
    //console.log($0);
    //console.log($1);
    return $1.toUpperCase();
});
console.log(formatStr);

